﻿package  
{
	import Box2D.Collision.b2AABB;
	import Box2D.Dynamics.b2Body;
	import Box2D.Dynamics.b2World;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.utils.getTimer;
	
	/**
	 * ...
	 * @author Georg Kamptner
	 */
	public class GameBody extends Sprite implements IGameBody
	{
		// -- variables & attributes ---------------------------------------------------------------------------
		protected var _body:b2Body;
		protected var _player:Player;
		protected var _creation_time:uint;
		protected var _game:Game;
		protected var _mouse_x:int = 0; // needed for velocity calculations while dragging
		protected var _mouse_y:int = 0; // needed for velocity calculations while dragging
		protected var _asset:DisplayObjectContainer;
		protected var _wincheck_count:int = 0;
		
		// -- getter & setter ----------------------------------------------------------------------------------
		public function get body():b2Body { return _body; }
		
		public function set body(value:b2Body):void 
		{
			_body = value;
		}
		
		public function get player():Player { return _player; }
		
		public function set player(value:Player):void 
		{
			_player = value;
		}
		
		public function get wincheck_count():int { return _wincheck_count; }
		
		public function set wincheck_count(value:int):void 
		{
			_wincheck_count = value;
			//(_asset.getChildByName("wincheck_count_txt") as TextField).text = "" + value;
		}
		
		// -- constructor --------------------------------------------------------------------------------------
		public function GameBody(body:b2Body, game:Game, asset_class:Class) 
		{
			_body = body;
			_creation_time = getTimer();
			_game = game;
			_asset = new asset_class();
			addChild(_asset);
		}
		
		// -- methods ------------------------------------------------------------------------------------------
		public function enableDragAndDrop():void
		{
		}
		
		public function disableDragAndDrop():void
		{
		}
		
		public function changeAssetTo(asset_class:Class):void
		{
			removeChild(_asset);
			_asset = new asset_class();
			addChild(_asset);
		}
		
		
		public function destroy():void
		{
			disableDragAndDrop();
			_mouse_x = 0;
			_mouse_y = 0;
			_creation_time = 0;
			_game.world.removeBox(_body);
			_body = null;
			_game = null;
		}
		
	}
	
}